from wtforms import Form
from wtforms.fields import StringField, PasswordField, IntegerField
from wtforms.validators import DataRequired, Email, Length, EqualTo, ValidationError, NumberRange
from .base_validate import ValidateMixin


class UserPutValidate(Form, ValidateMixin):
    nick_name = StringField(validators=[DataRequired(message='昵称不能为空')])
    tel = StringField()
    gender = IntegerField(validators=[])

    def validate_tel(self, field):
        self.check_mobile(field, need=False)

    def validate_gender(self, field):
        if not field._value():
            return
        if field._value() not in [0, 1]:
            raise ValidationError(u'gender必须为数字0或1')
